home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / blankery / blanker / source / messaging.c < prev    next >
C/C++ Source or Header  |  1993-08-08  |  4KB  |  154 lines

  1. /*
  2.  *    Copyright (c) 1993 Michael D. Bayne.
  3.  *    All rights reserved.
  4.  *
  5.  *    Please see the documentation accompanying the distribution for distribution and disclaimer information.
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <exec/memory.h>
  10. #include <exec/ports.h>
  11.  
  12. #include <dos/dos.h>
  13. #include <dos/dostags.h>
  14.  
  15. #include <intuition/intuition.h>
  16.  
  17. #include <clib/exec_protos.h>
  18. #include <clib/dos_protos.h>
  19. #include <clib/alib_protos.h>
  20. #include <clib/intuition_protos.h>
  21. #include <clib/utility_protos.h>
  22. #include <clib/graphics_protos.h>
  23. #include <clib/reqtools_protos.h>
  24.  
  25. #include "Blanker.h"
  26. #include "defs.h"
  27.  
  28. #include "protos/main.h"
  29. #include "protos/cxhand.h"
  30. #include "protos/winhand.h"
  31. #include "protos/prefs.h"
  32.  
  33. struct    Task    *bTask = 0L, *tmpTask = 0L;
  34.  
  35. UBYTE    *msgs[] = { "BM_DOBLANK", "BM_DOPREFS", "BM_DOQUIT" };
  36.  
  37. VOID DefaultBlanker( VOID )
  38. {
  39.     struct    Screen    *Scr;
  40.     UWORD   CTable[] = { 0x0222, 0x0AAA, 0x0AAA };
  41.  
  42.     Scr = OpenScreenTags( 0l, SA_DisplayID, bPrefs->bp_Mode, SA_Depth, bPrefs->bp_Depth, SA_Quiet, TRUE,
  43.         SA_Overscan, OSCAN_STANDARD, SA_Behind, TRUE, TAG_DONE );
  44.     LoadRGB4( &(Scr->ViewPort), CTable, 2 );
  45.     ScreenToFront( Scr );
  46.  
  47.     Wait( SIGBREAKF_CTRL_C );
  48.     SetSignal( 0L, cxBlankFlag );
  49.  
  50.     CloseScreen( Scr );
  51. }
  52.  
  53. LONG sendModMsg( ULONG Type, struct MsgPort *modulePort )
  54. {
  55.     struct BlankerMessage *bMsg;
  56.  
  57. #ifdef STDIO
  58.     printf( "Sending message: %s (%d).\n", msgs[Type-11], Type );
  59. #endif
  60.     if( modulePort ) {
  61.         if(!( bMsg = AllocMem( sizeof( struct BlankerMessage ), MEMF_CLEAR|MEMF_PUBLIC ))) return( 1 );
  62.  
  63.         bMsg->bm_Mess.mn_ReplyPort = blankerPort;
  64.         bMsg->bm_Mess.mn_Length = sizeof( struct BlankerMessage );
  65.         bMsg->bm_Task = ( struct Task * )( &bTask );
  66.         bMsg->bm_Type = Type;
  67.         bMsg->bm_Mod  = bPrefs->bp_Mode;
  68.         bMsg->bm_Dep  = bPrefs->bp_Depth;
  69.         bMsg->bm_Data = bPrefs->bp_Data;
  70. #ifdef STDIO
  71.         printf( "Putting message to port.\n" );
  72. #endif
  73.         PutMsg( modulePort, ( struct Message * )( bMsg ));
  74.         WaitPort( blankerPort );
  75.         FreeMem( GetMsg( blankerPort ), sizeof( struct BlankerMessage ));
  76. #ifdef STDIO
  77.         printf( "Received reply from module.\n" );
  78. #endif
  79.         switch( Type ) {
  80.         case BM_DOBLANK:
  81.             bTask = tmpTask;
  82.             break;
  83.         case BM_DOQUIT:
  84.             modulePort = 0L;
  85.             break;
  86.         default:
  87.             break;
  88.         }
  89.     } else if( Type == BM_DOBLANK ) {
  90.         bTask = Task;
  91.         DefaultBlanker();
  92.     }
  93.  
  94.     return( 0 );
  95. }
  96.  
  97. VOID loadModule( ULONG loadPrefs )
  98. {
  99.     BPTR    checkExists;
  100.     struct BlankerMessage *initMsg;
  101.  
  102.     sendModMsg( BM_DOQUIT, modulePort );
  103.  
  104.     if( checkExists = Open( doPath( bPrefs->bp_Name, bPrefs->bp_Dir ), MODE_OLDFILE ) ) {
  105.         Close( checkExists );
  106. #ifdef STDIO
  107.         printf( "Module %s exists, loading...\n", bPrefs->bp_Name );
  108. #endif
  109.         SystemTags( doPath( bPrefs->bp_Name, bPrefs->bp_Dir ), NP_FreeSeglist, TRUE, SYS_Asynch, TRUE,
  110.             SYS_Input, Open( "NIL:", MODE_OLDFILE ), SYS_Output, Open( "NIL:", MODE_OLDFILE ),
  111.             TAG_END );
  112.  
  113.         WaitPort( blankerPort );
  114. #ifdef STDIO
  115.         printf( "Received modDidInit message.\n" );
  116. #endif
  117.         if( initMsg = ( struct BlankerMessage * )GetMsg( blankerPort )) {
  118.             modulePort = ( struct MsgPort * )initMsg->bm_Mess.mn_ReplyPort;
  119.             tmpTask = initMsg->bm_Task;
  120.  
  121.             if( initMsg->bm_Dep ) {
  122.                 bPrefs->bp_Depth = initMsg->bm_Dep;
  123.                 bPrefs->bp_Flags &= ~BS_ASKDEP;
  124.             } else bPrefs->bp_Flags |= BS_ASKDEP;
  125.  
  126.             if( initMsg->bm_Mod != INVALID_ID ) {
  127.                 bPrefs->bp_Mode = initMsg->bm_Mod;
  128.                       bPrefs->bp_Flags &= ~BS_ASKSCR;
  129.             } else bPrefs->bp_Flags |= BS_ASKSCR;
  130.  
  131.             if( loadPrefs ) {
  132.                 bPrefs->bp_Flags &= ~BS_NOPRFS;
  133.                 if( initMsg->bm_Data ) CopyMem( initMsg->bm_Data, bPrefs->bp_Data, 512 );
  134.                 else bPrefs->bp_Flags |= BS_NOPRFS;
  135.             }
  136.             CopyMem( initMsg->bm_Info, modInfo, 64 );
  137.             bPrefs->bp_Flags |= BS_VALMOD;
  138.  
  139.             FreeMem( initMsg, sizeof( struct BlankerMessage ));
  140.         }
  141.     } else {
  142.         CopyMem( "No module loaded.", modInfo, 18 );
  143.         bPrefs->bp_Flags |= BS_ASKDEP;
  144.         bPrefs->bp_Flags |= BS_ASKSCR;
  145.         bPrefs->bp_Flags &= ~BS_VALMOD;
  146.         bPrefs->bp_Flags |= BS_NOPRFS;
  147.     }
  148.  
  149.     if( BlankerWnd && loadPrefs ) {
  150.         setPrefs( bPrefs, GD_MODINFO );
  151.         setPrefs( bPrefs, GD_MDISPLAY );
  152.     }
  153. }
  154.